/***************************************************************************
 *   Copyright (C) 2004 by cyril dupuit                                    *
 *   cyrildupuit@hotmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

//*****************************************************************************
// Nom du module : Dentry.c
// Description : Ce module est utilise pour gerer le system de fichiers virtuel
//*****************************************************************************
 
// Historique :
// 24/01/05 : Creation du module V1.0

#include "Kernel/Types.h"
#include "Config.h"
#include "Arch/Arch.h"
#include "Kernel/Core.h"
#include "Kernel/Semaphor.h"
#include "Kernel/List.h"
#include "FileSys/vfs/Dentry.h"
#include "FileSys/vfs/Vfs.h"
#include "Arch/Pentium/Kernel/malloc.h"
#include "Kernel/Errors.h"
#include "Lib/StdLib/string.h"
#include "Lib/LinkList.h"
#include "Lib/Stack.h"
#include "Lib/Queue.h"

//*****************************************************************************
// Variables externes :
//*****************************************************************************

extern struct VfsHead Vfs;

//*****************************************************************************
// Prototpes :
//*****************************************************************************

static struct VfsDentry * VfsDentryEmptyCreate(void);

//*****************************************************************************
// Corps des fonctions/procedures
//*****************************************************************************

//*****************************************************************************
// But de la fonction : Initialiser la destion des dentry
// Entree : Aucune
// Parametre retourne : TRUE
//*****************************************************************************
Status_t VfsDentryInit(void)
{
	unsigned int Size;
	struct VfsDentry * pDentry;
	
	ListInit(Vfs.pUsedList);
	Vfs.UsedCount = 0;
	
	ListInit(Vfs.pLruList);
	Vfs.LruCount = 0;
	
	ListInit(Vfs.pFreeList);
	Vfs.FreeCount = 0;
	
	Size = DENTRY_HASH_TABLE_SIZE * sizeof(struct VfsDentry *);
	
	Vfs.pDentryHash = (struct VfsDentry * *)kmalloc(Size);
	if(Vfs.pDentryHash == NULL)
	{//Memoire disponible insuffisante
		return ERROR;
	}
	//Initialiser le tableau
	memset(Vfs.pDentryHash, 0, Size);
	
	for(Size = 0; Size < DENTRY_UNUSED_COUNT; Size++)
	{//Creation du tampon des objets Dentry inutilises
		pDentry = VfsDentryEmptyCreate();
		if(pDentry == NULL) return ERROR;
		ListAddTail(Vfs.pFreeList, pDentry);
		Vfs.FreeCount++;
	}
	
	return TRUE;
}

//*****************************************************************************
// But de la fonction : Allouer un descripteur de repertoire et l'initialiser
// a 0
// Entree : Aucune
// Parametre retourne : Pointeur sur le descripteur de repertoire alloue
//*****************************************************************************
static struct VfsDentry * VfsDentryEmptyCreate(void)
{
	struct VfsDentry * pDentry;
	
	pDentry = (struct VfsDentry *)kmalloc(sizeof(struct VfsDentry));
	if(pDentry == NULL) return NULL;
	
	memset(pDentry, 0, sizeof(struct VfsDentry));
	
	return pDentry;
}

//*****************************************************************************
